From 98ab38038dfebb056f5dd98236f2a41a1b97372e Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 20 Jul 2010 22:28:50 +0000 Subject: [PATCH] * Split Mysql/Sqlite updates into their own files * Rename Update -> DatabaseUpdaters to be more consistent with DatabaseInstaller * Made DatabaseUpdaters abstract and merged the Updaters interface in, had Mysql/Oracle/Sqlite subclass it. Entry point is now factory DatabaseUpdaters::newForDB() --- includes/AutoLoader.php | 8 +- .../{Update.php => DatabaseUpdater.php} | 45 +++++++---- .../{Updaters.php => MysqlUpdater.php} | 79 +------------------ includes/installer/SqliteUpdater.php | 40 ++++++++++ maintenance/updaters.inc | 2 +- 5 files changed, 77 insertions(+), 97 deletions(-) rename includes/installer/{Update.php => DatabaseUpdater.php} (82%) rename includes/installer/{Updaters.php => MysqlUpdater.php} (77%) create mode 100644 includes/installer/SqliteUpdater.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index cae857ac75..e893189ac3 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -416,20 +416,20 @@ $wgAutoloadLocalClasses = array( 'CliInstaller' => 'includes/installer/CliInstaller.php', 'Installer' => 'includes/installer/Installer.php', 'DatabaseInstaller' => 'includes/installer/DatabaseInstaller.php', + 'DatabaseUpdater' => 'includes/installer/DatabaseUpdater.php', 'LBFactory_InstallerFake' => 'includes/installer/Installer.php', 'LocalSettingsGenerator' => 'includes/installer/LocalSettingsGenerator.php', 'WebInstaller' => 'includes/installer/WebInstaller.php', 'WebInstallerPage' => 'includes/installer/WebInstallerPage.php', 'WebInstallerOutput' => 'includes/installer/WebInstallerOutput.php', 'MysqlInstaller' => 'includes/installer/MysqlInstaller.php', - 'MysqlUpdater' => 'includes/installer/Updaters.php', + 'MysqlUpdater' => 'includes/installer/MysqlUpdater.php', 'PostgresInstaller' => 'includes/installer/PostgresInstaller.php', 'SqliteInstaller' => 'includes/installer/SqliteInstaller.php', - 'SqliteUpdater' => 'includes/installer/Updaters.php', + 'SqliteUpdater' => 'includes/installer/SqliteUpdate.php', 'OracleInstaller' => 'includes/installer/OracleInstaller.php', - 'OracleUpdater' => 'includes/installer/Updaters.php', + 'OracleUpdater' => 'includes/installer/DatabaseUpdater.php', 'Update' => 'includes/installer/Update.php', - 'Updaters' => 'includes/installer/Updaters.php', # includes/job 'DoubleRedirectJob' => 'includes/job/DoubleRedirectJob.php', diff --git a/includes/installer/Update.php b/includes/installer/DatabaseUpdater.php similarity index 82% rename from includes/installer/Update.php rename to includes/installer/DatabaseUpdater.php index 9e1f1a486c..c817f8051b 100644 --- a/includes/installer/Update.php +++ b/includes/installer/DatabaseUpdater.php @@ -4,31 +4,29 @@ * Class for handling database updates. Roughly based off of updaters.inc, with * a few improvements :) */ -class Update { +abstract class DatabaseUpdater { /** * Array of updates to perform on the database - * + * * @var array */ protected $updates = array(); protected $db; - - protected $updater; - public function __construct( $db ) { + protected function __construct( $db ) { $this->db = $db; - switch( $this->db->getType() ) { + } + + public static function newForDB( $db ) { + switch( $db->getType() ) { case 'mysql': - $this->updater = new MysqlUpdater(); - break; + return new MysqlUpdater( $db ); case 'sqlite': - $this->updater = new SqliteUpdater(); - break; + return new SqliteUpdater( $db ); case 'oracle': - $this->updater = new OracleUpdater(); - break; + return new OracleUpdater( $db ); default: throw new MWException( __METHOD__ . ' called for unsupported $wgDBtype' ); } @@ -55,9 +53,9 @@ class Update { // If the updatelog table hasn't been upgraded, we can't use the new // style of recording our steps. Run all to be safe if( !$this->canUseNewUpdatelog() ) { - $this->updates = $this->updater->getUpdates(); + $this->updates = $this->getCoreUpdateList(); } else { - foreach( $this->updater->getUpdates() as $version => $updates ) { + foreach( $this->getCoreUpdateList() as $version => $updates ) { $appliedUpdates = $this->getAppliedUpdates( $version ); if( !$appliedUpdates || $appliedUpdates != $updates ) { $this->updates[ $version ] = $updates; @@ -149,5 +147,20 @@ class Update { ); } } - -} \ No newline at end of file + + /** + * Get an array of updates to perform on the database. Should return a + * mutli-dimensional array. The main key is the MediaWiki version (1.12, + * 1.13...) with the values being arrays of updates, identical to how + * updaters.inc did it (for now) + * + * @return Array + */ + protected abstract function getCoreUpdateList(); +} + +class OracleUpdater extends DatabaseUpdater { + protected function getCoreUpdateList() { + return array(); + } +} diff --git a/includes/installer/Updaters.php b/includes/installer/MysqlUpdater.php similarity index 77% rename from includes/installer/Updaters.php rename to includes/installer/MysqlUpdater.php index c21dc675a3..07dad0ca00 100644 --- a/includes/installer/Updaters.php +++ b/includes/installer/MysqlUpdater.php @@ -1,29 +1,10 @@ array( array( 'add_field', 'ipblocks', 'ipb_id', 'patch-ipblocks.sql' ), @@ -174,58 +155,4 @@ class MysqlUpdater implements Updaters { ), ); } - -} - -/** - * Sqlite implementation. - */ -class SqliteUpdater implements Updaters { - - public function getUpdates() { - return array( - '1.14' => array( - array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ), - array( 'do_active_users_init' ), - array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ), - array( 'sqlite_initial_indexes' ), - ), - '1.15' => array( - array( 'add_table', 'change_tag', 'patch-change_tag.sql' ), - array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ), - array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ), - ), - '1.16' => array( - array( 'add_table', 'user_properties', 'patch-user_properties.sql' ), - array( 'add_table', 'log_search', 'patch-log_search.sql' ), - array( 'do_log_search_population' ), - array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ), - array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ), - array( 'add_table', 'external_user', 'patch-external_user.sql' ), - array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ), - array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ), - array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ), - array( 'do_update_transcache_field' ), - array( 'sqlite_setup_searchindex' ), - ), - '1.17' => array( - array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ), - array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ), - array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ), - array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ), - ), - ); - } - } - -/** - * Oracle implementation. - */ -class OracleUpdater implements Updaters { - - public function getUpdates() { - return array(); - } - -} \ No newline at end of file diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php new file mode 100644 index 0000000000..2bace6e048 --- /dev/null +++ b/includes/installer/SqliteUpdater.php @@ -0,0 +1,40 @@ + array( + array( 'add_field', 'site_stats', 'ss_active_users', 'patch-ss_active_users.sql' ), + array( 'do_active_users_init' ), + array( 'add_field', 'ipblocks', 'ipb_allow_usertalk', 'patch-ipb_allow_usertalk.sql' ), + array( 'sqlite_initial_indexes' ), + ), + '1.15' => array( + array( 'add_table', 'change_tag', 'patch-change_tag.sql' ), + array( 'add_table', 'tag_summary', 'patch-change_tag.sql' ), + array( 'add_table', 'valid_tag', 'patch-change_tag.sql' ), + ), + '1.16' => array( + array( 'add_table', 'user_properties', 'patch-user_properties.sql' ), + array( 'add_table', 'log_search', 'patch-log_search.sql' ), + array( 'do_log_search_population' ), + array( 'add_field', 'logging', 'log_user_text', 'patch-log_user_text.sql' ), + array( 'add_table', 'l10n_cache', 'patch-l10n_cache.sql' ), + array( 'add_table', 'external_user', 'patch-external_user.sql' ), + array( 'add_index', 'log_search', 'ls_field_val', 'patch-log_search-rename-index.sql' ), + array( 'add_index', 'change_tag', 'change_tag_rc_tag', 'patch-change_tag-indexes.sql' ), + array( 'add_field', 'redirect', 'rd_interwiki', 'patch-rd_interwiki.sql' ), + array( 'do_update_transcache_field' ), + array( 'sqlite_setup_searchindex' ), + ), + '1.17' => array( + array( 'add_table', 'iwlinks', 'patch-iwlinks.sql' ), + array( 'add_index', 'iwlinks', 'iwl_prefix_from_title', 'patch-rename-iwl_prefix.sql' ), + array( 'add_field', 'updatelog', 'ul_value', 'patch-ul_value.sql' ), + array( 'add_field', 'interwiki', 'iw_api', 'patch-iw_api_and_wikiid.sql' ), + ), + ); + } +} diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index ed3f619eed..246d6d6a1f 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -949,7 +949,7 @@ function do_all_updates( $shared = false, $purge = true ) { } global $wgDatabase; - $up = new Update( $wgDatabase ); + $up = DatabaseUpdater::newForDb( $wgDatabase ); $up->doUpdates(); wfOut( "Deleting old default messages (this may take a long time!)..." ); -- 2.20.1